package com.google.code.bankagregator.entities;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * Credit value object
 */
@Entity
public class Credit extends Product {

    /**
     * Credit rate
     */
    private double creditRate;
    /**
     * Max money amount for product
     */
    private int maxAmount;
    /**
     * Min money amount for product
     */
    private int minAmount;
    /**
     * Credit term (in number of days)
     */
    private int term;
    /**
     * Credit type
     */
    @Enumerated(EnumType.STRING)
    private CreditType type;
    /**
     *
     */
    private Double prepayment;

    public Credit() {

    }

    public Credit(int id, String added, double creditRate, String currency,
                  int minAmt, int maxAmt, String name, double prepayment, String state, int term,
                  String crType, String url, String bankName, String bankUrl) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-mm-dd HH:mm:ss");


        this.id = id;
        try {
            this.added = dateFormat.parse(added);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        this.creditRate = creditRate;
        this.currency = Currency.valueOf(currency);
        this.minAmount = minAmt;
        this.maxAmount = maxAmt;
        this.name = name;
        this.prepayment = prepayment;
        this.state = State.valueOf(state);
        this.term = term;
        this.type = CreditType.valueOf(crType);
        this.url = url;

        Bank bank = new Bank();
        bank.setName(bankName);
        bank.setUrl(bankUrl);

        this.bank = bank;
    }

    public double getCreditRate() {
        return creditRate;
    }

    public void setCreditRate(double creditRate) {
        this.creditRate = creditRate;
    }

    public int getMaxAmount() {
        return maxAmount;
    }

    public void setMaxAmount(int maxAmount) {
        this.maxAmount = maxAmount;
    }

    public int getMinAmount() {
        return minAmount;
    }

    public void setMinAmount(int minAmount) {
        this.minAmount = minAmount;
    }

    public int getTerm() {
        return term;
    }

    public void setTerm(int term) {
        this.term = term;
    }

    public CreditType getType() {
        return type;
    }

    public void setType(CreditType type) {
        this.type = type;
    }

    public Double getPrepayment() {
        return prepayment;
    }

    public void setPrepayment(Double prepayment) {
        this.prepayment = prepayment;
    }

    @Override
    public String toString() {
        return "Credit{" +
                "creditRate=" + creditRate +
                ", maxAmount=" + maxAmount +
                ", minAmount=" + minAmount +
                ", term=" + term +
                ", type=" + type +
                ", prepayment=" + prepayment +
                super.toString() +
                '}';
    }
}
